#ifndef _DSWCONSOLE_GPRS_SESSION_BASE_H
#define _DSWCONSOLE_GPRS_SESSION_BASE_H

#include "base.h"

typedef struct{
	int nSocketIndex;
	char* pData;
	int nLen;
	char* pSendPos;
	int nSendedLen;
} ST_GPRS_DATA_T, *LPST_GPRS_DATA_T;

#define CLEAR_GPRS_DATA(x) {if (x.pData) delete x.pData;memset(&x, 0, sizeof(x));}

#define MAX_GPRS_TCP_SENDLEN 64

class CDswconsole_gprs_session_base
{
public:
	CDswconsole_gprs_session_base(LPST_ENV_T pEnv, struct bufferevent *pBev);
	virtual ~CDswconsole_gprs_session_base();
public:
	virtual void ProcessData(char* pData, int nLen){};
	void OnGPRSSendedData(int nState);
	void OnGPRSPushedData(int nState);
protected:
	void SendData(char* pData, int nLen){evbuffer_add(bufferevent_get_output(m_pBev), pData, nLen);};
	void MakeGPRSSendData(int nSocketIndex, char* pData, int nLen);
	void SendTcpData(LPST_GPRS_DATA_T pGprsData);
	void SetSocketIndex(int nSocketIndex){m_nSocketIndex = nSocketIndex;};

	static void cbPushTaskFunc(int fd, short events, void* ctx){((CDswconsole_gprs_session_base*)ctx)->PushTaskFunc(fd, events);};
	void PushTaskFunc(int fd, short events);
private:
	virtual void OnCommTimeOut(){};
protected:
	LPST_ENV_T m_pEnv;
	struct bufferevent *m_pBev;
	ST_GPRS_DATA_T m_nGprsSendData;
	int m_nSocketIndex;
	timer_param_t m_nTask_Push;
	int m_nPushCount;
};

#endif

